<template>
  <div class="list-page">
    <div class="list-page-search" v-if="tableInfo.showSearch">
      <NForm inline :model="tableInfo.queryForm" label-placement="left">
        <NFormItem label="类型">
          <n-select
            style="width: 150px"
            clearable
            v-model:value="tableInfo.queryForm.type"
            :options="typeEnum"
          />
        </NFormItem>
        <NFormItem label="关联资源">
          <NInput
            v-model:value="tableInfo.queryForm.about_id"
            placeholder="请输入关联id"
            clearable
            style="width: 200px"
          />
        </NFormItem>
        <NFormItem label="用户">
          <y-selectpcuser v-model="tableInfo.queryForm.userId" />
        </NFormItem>
        <NFormItem>
          <NButton type="primary" @click="queryData">
            <template #icon>
              <n-icon>
                <i class="esayIcon esayIcon-sousuo"></i>
              </n-icon>
            </template>
            <span>搜索</span>
          </NButton>
        </NFormItem>
      </NForm>
    </div>
    <div class="list-page-main">
      <div class="pb20 flex flex-between">
        <div></div>
        <div>
          <n-button
            tertiary
            circle
            @click="tableInfo.showSearch = !tableInfo.showSearch"
          >
            <template #icon>
              <i class="esayIcon esayIcon-sousuo"></i>
            </template>
          </n-button>
          <n-button class="ml15" tertiary circle @click="handToast">
            <template #icon>
              <i class="esayIcon esayIcon-daochu"></i>
            </template>
          </n-button>
          <n-button class="ml15" tertiary circle @click="handToast">
            <template #icon>
              <i class="esayIcon esayIcon-daoru"></i>
            </template>
          </n-button>
        </div>
      </div>
      <NDataTable
        v-model:checked-row-keys="tableInfo.checkedRowKeys"
        style="flex: 1"
        flex-height
        :columns="columns"
        :row-key="rowKey"
        :loading="tableInfo.listLoading"
        :data="tableInfo.tableData"
      />
      <div class="pagination mt20">
        <NPagination
          v-model:page="tableInfo.queryForm.pageNo"
          :page-count="tableInfo.total"
          :page-sizes="tableInfo.pageSizes"
          show-quick-jumper
          show-size-picker
          @updatePage="pageChange"
          @updatePageSize="sizeChange"
        />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import {
  NButton,
  NDataTable,
  NForm,
  NFormItem,
  NIcon,
  NInput,
  NPagination,
  NSelect,
  useMessage
} from 'naive-ui'
import type { SelectOption } from 'naive-ui'
import type { DataTableColumns } from 'naive-ui'
import { useApi } from '@/hooks/useApi'
const rowKey = (row: any) => row.id
import userApi from '@/service/api/operation/user'
import YSelectpcuser from '@/components/yang/yselectpcuser/index.vue'
import typeEnum, { getInterTypeName } from '@/enum/InterTypeEnum'
const { pageChange, sizeChange, tableInfo, queryData } = useApi({
  getData: userApi.logList,
  dataMap: (data: any) => {
    return data.map((el: any) => {
      el.type = getInterTypeName(el.type)
      return el
    })
  },
  initForm: {
    userId: null
  }
})
/**
 *  获取列表
 * */
const columns: DataTableColumns<any> = [
  {
    title: '关联id',
    key: 'about_id',
    width: 80
  },
  {
    title: '类型',
    key: 'type'
  },
  {
    title: '积分',
    key: 'integral'
  },
  {
    title: '总积分',
    key: 'allIntegral'
  },
  {
    title: '用户',
    key: 'nickname'
  },
  {
    title: '说明',
    key: 'content',
    width: 200,
    ellipsis: {
      tooltip: true
    }
  },
  {
    title: '日期',
    key: 'create_at'
  }
]

const toast = useMessage()
const handToast = () => {
  toast.warning('开发中')
}
</script>

<style lang="scss" scoped></style>
